package softtech.app.secretcaller;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.Context;
import android.util.Log;

public class ToolsSaveFile {
	
	public void SaveContentFile(Context context,String fileName,String data){
		String noiDung = data;
		if(!fileName.contains(".txt")){
			fileName = fileName + ".txt";
		}
		try {
			FileOutputStream outPut=context.openFileOutput(fileName, Context.MODE_PRIVATE);
			byte[] epmang = noiDung.getBytes();
			outPut.write(epmang);
			Log.e("GHI FILE THANH CONG","GHI FILE "+fileName +" THANH CONG");
		} catch (Exception e) {
			Log.e("ghi file xit","loi:"+e.toString());
		}
	}
	
	public String LoadContentFile(Context context,String fileName){
		String cache="";
		if(!fileName.contains(".txt")){
			fileName = fileName + ".txt";
		}
		FileInputStream inPut;
		try {

			inPut = context.openFileInput(fileName);

			BufferedReader reader = new BufferedReader(new InputStreamReader(inPut));
			try {
				String c =null;
				
				while((c=reader.readLine())!=null){
					cache+=c;
				}
			} catch (IOException e) {

				Log.e("loi","loi:"+e.toString());
			}
		} catch (FileNotFoundException e) {

			Log.e("loi","loi:"+e.toString());
		}
		
		return cache;
	}
	
	/**
	 * 
	 * @param s
	 * @return
	 * true: not null
	 * false: null
	 */
	public static Boolean checkStringNotNull(String s ){
		return (s!=null && !s.equals(null) && s.length() >= 1 );
	}
	/**
	 * check string not null
	 * @param s
	 * @param minLength
	 * @return
	 * true: not null
	 * false: null
	 */
	public static Boolean checkStringNotNull(String s , int minLength){
		return (s!=null && !s.equals(null) && s.length() >=minLength );
	}
	
}
